#!/bin/bash
#H1-------R1-------H2

ip netns add H1
ip netns add R1
ip netns add H2

#H1
ip link add name H1_R1 type veth peer name R1_H1
ip link set H1_R1 netns H1
ip netns exec H1 bash -c \
'
	ip link set lo up
	ip link set H1_R1 up

	ip addr add 192.168.0.1/24 dev H1_R1
	ip route add 10.0.0.0/24 via 192.168.0.254
'

#R1
ip link add name R1_H2 type veth peer name H2_R1
ip link set R1_H1 netns R1
ip link set R1_H2 netns R1
ip netns exec R1 bash -c \
'
	ip link set lo up
	ip link set R1_H1 up
	ip link set R1_H2 up

	ip link add name vrf_ab type vrf table 100
	ip link set vrf_ab up
	ip link set R1_H2 master vrf_ab

	ip rule add to 10.0.0.1 lookup 100
	ip addr add 192.168.0.254/24 dev R1_H1
	ip addr add 10.0.0.254/24 dev R1_H2
'

#H2
ip link set H2_R1 netns H2
ip netns exec H2 bash -c \
'
	ip link set lo up
	ip link set H2_R1 up

	ip addr add 10.0.0.1/24 dev H2_R1
	ip route add 192.168.0.0/24 via 10.0.0.254
'
